package com.zx.callback.common.handler;

import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.List;

/**
 * Created by zhaox on 16/5/9.
 */
public class PageBean<T> implements Serializable {

    private static final long serialVersionUID = 5444599099748992156L;

    private long total;        //总记录数
    private List<T> list;    //结果集
    private int curPage = 1 ;    // 当前页
    private int pageSize = 10;    // 每页记录数 默认20
    private int totalPages;        // 总页数
    private int size;        // 当前页的数量 <= pageSize，该属性来自ArrayList的size属性

    private T t;//  对象

    public PageBean() {
        super();
    }

    public PageBean(int curPage,int pageSize){
        this.curPage = curPage;
        this.pageSize = pageSize;
    }

    /**
     * 包装Page对象，因为直接返回Page对象，在JSON处理以及其他情况下会被当成List来处理，
     * 而出现一些问题。
     * @param list          page结果
     */
    public PageBean(List<T> list) {
        this.list = list;
        if (list instanceof Page) {
            Page<T> page = (Page<T>) list;
            this.curPage = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.total = page.getTotal();
            this.totalPages = page.getPages();
            this.size = page.size();
        }
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getCurPage() {
        return curPage;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }
}
